//先进先出
class Queue{
    constructor(){
        this.items = {};
        this.count = 0; //记录键的
        this.lowercount = 0; //记录最前面元素的键
    }   
    //添加
    enqueue(element){
        this.items[this.count] = element;
        this.count ++;
    }

    //删除
    dequeue(){
        let ele = this.items[this.lowercount]; //要删除的元素
        delete this.items[this.lowercount]; //删掉队列最前面的元素
        this.lowercount++;
        return ele
    }

    //返回队列中的第一个元素
    peek(){
        return this.items[this.lowercount]
    }

    isEmpty(){
        return this.count - this.lowercount === 0
    }

    size(){
        return this.count - this.lowercount
    }

    clear(){
        this.items = {};
        this.count = 0; //记录键的
        this.lowercount = 0; //记录最前面的键
    }

    toString(){
        let str = '';
        for(let i = this.lowercount;i<this.count;i++){
           console.log(this.items[i])
           str += `,${this.items[i]}`
       } 
       return str.slice(1)
    }
}

let q = new  Queue();

q.enqueue('a');

q.enqueue('b');

// console.log(q.dequeue());

console.log(q.toString());